﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ncp.Business.Common;
using ncp.Business;
using ncp.Web.member;

namespace ncp.Web.uc
{
    public partial class MemberIndex : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var userInfo = WebMasterCookie.GetCookie();
            if (!IsPostBack)
            {
                if (userInfo == null)
                {
                    Response.Redirect("/login.html");
                }
                GetUserInfo(userInfo);
            }
        }

        //根据cookie信息查询用户相关信息
        private void GetUserInfo(UserInfo userInfo)
        {
            var table = ClientInfoBll.GetClientInfoTable("Client_Id=" + userInfo.Id, "Client_Id asc",  CommonConst.DB_Name);
            if (table.Rows.Count==0)
            {
                Response.Redirect("/login.aspx");
            }
            lbIntegral.Text = table.Rows[0]["User_Points"].ToString();
            lbrating.Text = ClientInfoBll.GetClientLevel(table.Rows[0]["User_Points"].ToString(), CommonConst.DB_Name);
            var shopId = CommonBll.BuildShopId(int.Parse(userInfo.Id));
            lbGotoShop.Text = string.Format("<a href=\"/shop{0}/about.html\" target=\"_blank\">我的商铺</a>", shopId);
        }
    }
}
